{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "a5bd9ec2-856f-46d3-8f15-8fd538782eb8",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-10T06:00:02.277577Z",
     "iopub.status.busy": "2023-02-10T06:00:02.277063Z",
     "iopub.status.idle": "2023-02-10T06:00:02.482848Z",
     "shell.execute_reply": "2023-02-10T06:00:02.482419Z",
     "shell.execute_reply.started": "2023-02-10T06:00:02.277423Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/lyz/.local/lib/python3.9/site-packages/requests/__init__.py:102: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (5.0.0)/charset_normalizer (2.0.11) doesn't match a supported version!\n",
      "  warnings.warn(\"urllib3 ({}) or chardet ({})/charset_normalizer ({}) doesn't match a supported \"\n"
     ]
    }
   ],
   "source": [
    "import codecs\n",
    "import subprocess\n",
    "import requests\n",
    "import glob\n",
    "import cv2\n",
    "import os\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "167ad67c-100d-4d0c-9a98-0a0c92ee48af",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-10T06:00:02.484068Z",
     "iopub.status.busy": "2023-02-10T06:00:02.483837Z",
     "iopub.status.idle": "2023-02-10T06:00:02.488654Z",
     "shell.execute_reply": "2023-02-10T06:00:02.487951Z",
     "shell.execute_reply.started": "2023-02-10T06:00:02.484051Z"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "def download_file(cmd):\n",
    "    if 'ts' == cmd[-2:]:\n",
    "        if os.path.exists(cmd.split('/')[-1] + '.st'):\n",
    "            subprocess.check_output(cmd, shell=True, timeout=5)\n",
    "            return\n",
    "\n",
    "        if os.path.exists(cmd.split('/')[-1]):\n",
    "            return\n",
    "        \n",
    "    elif 'm3u8' in cmd and os.path.exists(cmd.split('/')[-1]):\n",
    "        return\n",
    "    \n",
    "    try:\n",
    "        subprocess.check_output(cmd, shell=True, timeout=5)\n",
    "    except:\n",
    "        download_file(cmd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "775be4f3-5095-41ff-b56e-6f77bfd42f7b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2023-02-10T07:48:47.220710Z",
     "iopub.status.busy": "2023-02-10T07:48:47.220085Z",
     "iopub.status.idle": "2023-02-10T07:48:58.097057Z",
     "shell.execute_reply": "2023-02-10T07:48:58.096470Z",
     "shell.execute_reply.started": "2023-02-10T07:48:47.220650Z"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "346\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ffmpeg version 3.4.11-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers\n",
      "  built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)\n",
      "  configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --enable-gpl --disable-stripping --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librubberband --enable-librsvg --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-omx --enable-openal --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libopencv --enable-libx264 --enable-shared\n",
      "  libavutil      55. 78.100 / 55. 78.100\n",
      "  libavcodec     57.107.100 / 57.107.100\n",
      "  libavformat    57. 83.100 / 57. 83.100\n",
      "  libavdevice    57. 10.100 / 57. 10.100\n",
      "  libavfilter     6.107.100 /  6.107.100\n",
      "  libavresample   3.  7.  0 /  3.  7.  0\n",
      "  libswscale      4.  8.100 /  4.  8.100\n",
      "  libswresample   2.  9.100 /  2.  9.100\n",
      "  libpostproc    54.  7.100 / 54.  7.100\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_1.ts' for reading\n",
      "Input #0, hls,applehttp, from 'origin.m3u8':\n",
      "  Duration: 00:57:26.07, start: 0.000000, bitrate: 0 kb/s\n",
      "  Program 0 \n",
      "    Metadata:\n",
      "      variant_bitrate : 0\n",
      "    Stream #0:0: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp\n",
      "    Metadata:\n",
      "      variant_bitrate : 0\n",
      "    Stream #0:1: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709/bt709/unknown), 1920x1080 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 180k tbc\n",
      "    Metadata:\n",
      "      variant_bitrate : 0\n",
      "Output #0, mp4, to '基于柔性负荷任务的需量优化策略挑战赛.mp4':\n",
      "  Metadata:\n",
      "    encoder         : Lavf57.83.100\n",
      "    Stream #0:0: Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709/bt709/unknown), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 30 fps, 30 tbr, 90k tbn, 90k tbc\n",
      "    Metadata:\n",
      "      variant_bitrate : 0\n",
      "    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp\n",
      "    Metadata:\n",
      "      variant_bitrate : 0\n",
      "Stream mapping:\n",
      "  Stream #0:1 -> #0:0 (copy)\n",
      "  Stream #0:0 -> #0:1 (copy)\n",
      "Press [q] to stop, [?] for help\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_2.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_3.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_4.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_5.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_6.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_7.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_8.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_9.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_10.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_11.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_12.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_13.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_14.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_15.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_16.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_17.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_18.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_19.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_20.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_21.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_22.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_23.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_24.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_25.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_26.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_27.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_28.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_29.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_30.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_31.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_32.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_33.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_34.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_35.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_36.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_37.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_38.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_39.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_40.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_41.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_42.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_43.ts' for reading.4kbits/s speed= 834x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_44.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_45.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_46.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_47.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_48.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_49.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_50.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_51.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_52.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_53.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_54.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_55.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_56.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_57.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_58.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_59.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_60.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_61.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_62.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_63.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_64.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_65.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_66.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_67.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_68.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_69.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_70.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_71.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_72.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_73.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_74.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_75.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_76.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_77.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_78.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_79.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_80.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_81.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_82.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_83.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_84.ts' for reading17.1kbits/s speed= 829x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_85.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_86.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_87.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_88.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_89.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_90.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_91.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_92.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_93.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_94.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_95.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_96.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_97.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_98.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_99.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_100.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_101.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_102.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_103.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_104.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_105.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_106.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_107.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_108.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_109.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_110.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_111.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_112.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_113.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_114.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_115.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_116.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_117.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_118.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_119.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_120.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_121.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_122.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_123.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_124.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_125.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_126.ts' for reading3.9kbits/s speed= 832x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_127.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_128.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_129.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_130.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_131.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_132.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_133.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_134.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_135.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_136.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_137.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_138.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_139.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_140.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_141.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_142.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_143.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_144.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_145.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_146.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_147.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_148.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_149.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_150.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_151.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_152.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_153.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_154.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_155.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_156.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_157.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_158.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_159.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_160.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_161.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_162.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_163.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_164.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_165.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_166.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_167.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_168.ts' for reading5.0kbits/s speed= 832x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_169.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_170.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_171.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_172.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_173.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_174.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_175.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_176.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_177.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_178.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_179.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_180.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_181.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_182.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_183.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_184.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_185.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_186.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_187.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_188.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_189.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_190.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_191.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_192.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_193.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_194.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_195.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_196.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_197.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_198.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_199.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_200.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_201.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_202.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_203.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_204.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_205.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_206.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_207.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_208.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_209.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_210.ts' for reading9.9kbits/s speed= 834x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_211.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_212.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_213.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_214.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_215.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_216.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_217.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_218.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_219.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_220.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_221.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_222.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_223.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_224.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_225.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_226.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_227.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_228.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_229.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_230.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_231.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_232.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_233.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_234.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_235.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_236.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_237.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_238.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_239.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_240.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_241.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_242.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_243.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_244.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_245.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_246.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_247.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_248.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_249.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_250.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_251.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_252.ts' for reading9.6kbits/s speed= 836x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_253.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_254.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_255.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_256.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_257.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_258.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_259.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_260.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_261.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_262.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_263.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_264.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_265.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_266.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_267.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_268.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_269.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_270.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_271.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_272.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_273.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_274.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_275.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_276.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_277.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_278.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_279.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_280.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_281.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_282.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_283.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_284.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_285.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_286.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_287.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_288.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_289.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_290.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_291.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_292.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_293.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_294.ts' for reading6.9kbits/s speed= 838x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_295.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_296.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_297.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_298.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_299.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_300.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_301.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_302.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_303.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_304.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_305.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_306.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_307.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_308.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_309.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_310.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_311.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_312.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_313.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_314.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_315.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_316.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_317.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_318.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_319.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_320.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_321.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_322.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_323.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_324.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_325.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_326.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_327.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_328.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_329.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_330.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_331.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_332.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_333.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_334.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_335.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_336.ts' for reading20.1kbits/s speed= 838x    \n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_337.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_338.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_339.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_340.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_341.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_342.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_343.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_344.ts' for reading\n",
      "[hls,applehttp @ 0x5609b3907900] Opening 'origin.m3u8_345.ts' for reading\n",
      "frame=103383 fps=25037 q=-1.0 Lsize= 2241515kB time=00:57:26.12 bitrate=5328.4kbits/s speed= 835x    \n",
      "video:2103191kB audio:134615kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.165749%\n"
     ]
    }
   ],
   "source": [
    "url = 'https://myun-hw-s3.myun.tv/melj80jz/024kvy97/0evbzyol/5rbzxjz0/origin.m3u8'\n",
    "filename = '基于柔性负荷任务的需量优化策略挑战赛.mp4'\n",
    "\n",
    "ts = [url.replace('origin.m3u8', '') + x for x in requests.get(url).text.split('\\n') if '.ts' in x]\n",
    "\n",
    "cmds = []\n",
    "cmds.append('axel -a -n 5 ' + url)\n",
    "for x in ts:\n",
    "    cmds.append('axel -a -n 5 -T 10 ' + x)\n",
    "        \n",
    "print(len(cmds))\n",
    "\n",
    "for cmd in cmds:\n",
    "    try:\n",
    "        download_file(cmd)\n",
    "    except:\n",
    "        pass\n",
    "\n",
    "for cmd in cmds:\n",
    "    download_file(cmd)\n",
    "    \n",
    "subprocess.check_output(f'ffmpeg -i origin.m3u8 -c copy -bsf:a aac_adtstoasc {filename}', shell=True, timeout=5)\n",
    "for path in glob.glob('./origin*'):\n",
    "    os.unlink(path)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3.10"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "state": {},
    "version_major": 2,
    "version_minor": 0
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
